//-----------------------------------------------------------------------
//<copyright file="NhomHangDAO.cs
//Code generate by tools.
//</copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using PMS.Exceptions;
using System.Data.SqlClient;
using PMS.Entity;

namespace PMS.DAL
{
	public class NhomHangDAO : SQLDatabase, INhomHangDAO
	{

		#region Create NhomHang methods

		public NhomHang CreateNhomHang(NhomHang nhomHang)
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spNhomHangInsert");
				AddOutParameter(command, "@MaNH", SqlDbType.NVarChar, nhomHang.MaNH);
				AddInParameter(command, "@TenNH", SqlDbType.NVarChar, nhomHang.TenNH);
				AddInParameter(command, "@GhiChu", SqlDbType.NVarChar, nhomHang.GhiChu);

				ExecuteNonQuery(command);
                nhomHang.MaNH = (string)GetParameterValue(command, "@MaNH");
				return nhomHang;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access CreateNhomHangException", ex);
			}
		}

		#endregion

		#region Update NhomHang methods

		public void UpdateNhomHang(NhomHang nhomHang)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spNhomHangUpdate");

				AddInParameter(command, "@MaNH", SqlDbType.NVarChar, nhomHang.MaNH);
				AddInParameter(command, "@TenNH", SqlDbType.NVarChar, nhomHang.TenNH);
				AddInParameter(command, "@GhiChu", SqlDbType.NVarChar, nhomHang.GhiChu);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access UpdateNhomHangException", ex);
			}
		}

		#endregion

		#region Delete NhomHang methods

		public void DeleteNhomHang(NhomHang nhomHang)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spNhomHangDelete");

				AddInParameter(command, "@MaNH", SqlDbType.NVarChar, nhomHang.MaNH);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access DeleteNhomHangException", ex);
			}
		}

		#endregion

		#region Select methods

		#region GetAll NhomHang methods

		public NhomHangs GetAllNhomHang()
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spNhomHangGetList");
				NhomHangs Result = new NhomHangs();
				List<NhomHang> List = ExecuteQuery<NhomHang>(command,true);
				foreach(NhomHang item in List)
				{
					Result.Add(item);
				}
				return Result;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetAllNhomHangException", ex);
			}
		}

		#endregion


		#region GetNhomHang methods

		public NhomHang GetNhomHangByID(string maNH)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spNhomHangGet");

				AddInParameter(command, "@maNH", SqlDbType.NVarChar, maNH);

				return ExecuteQuery<NhomHang>(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetNhomHangBy ID Exception", ex);
			}
		}

		#endregion


		#endregion
	}
}//End Class
